<script>
// import BianJi from '@/components/bianji.vue'
import axios from 'axios'
import BianJi1 from '@/components/bianji1.vue'

export default {
  name: 'AdminZhuye',
  components: { BianJi1 },
  // components: { BianJi },
  data () {
    return {
      search: '',
      res: [],
      cx: true,
      editid: ''
    }
  },
  async created () {
    this.res = await axios.get('houtai/houtailist/')
    // console.log(this.res)
  },
  methods: {
    async handleEdit (index, row) {
      this.editid = row.id
      this.cx = false
      // this.yuanshuju = await this.$axios.get(`houtai/adminlist/${row.id}/`)
      // console.log(this.yuanshuju)
      // this.$store.commit('getbwlist', yuanshuju)
      // const edit = await this.$axios.put(`houtai/adminlist/${row.id}/`)
      // console.log(edit)
    },
    async handleDelete (index, row) {
      const imgsc = await this.$axios.delete(`houtai/uploadimg/${row.id}/`)
      if (imgsc.xinxi === '照片已删除') {
        location.reload()
      } else {
        alert('gitee照片删除失败')
      }
    }
  }
}
</script>
<!--      v-for="item in res" :key="item.id"-->
<template>
  <div>
    <el-button type="primary" style="background: #2c3e50;margin-left: 300px" round @click="cx=!cx">新增博文</el-button>
    <bian-ji1 :style="{background: '#42b983'}" :class="{cx:cx}" :yuanshuju="editid"></bian-ji1>
    <el-table
       :data="res.filter(data => !search || data.title.toLowerCase().includes(search.toLowerCase()))"
      style="width: 60%;margin: auto">
      <el-table-column
        label="id"
        prop="id">
      </el-table-column>
      <el-table-column
        label="标题"
        prop="title">
      </el-table-column>
      <el-table-column
        label="发布时间"
        prop="postdate">
      </el-table-column>
      <el-table-column
        label="分类"
        prop="fenlei">
      </el-table-column>
       <el-table-column
        label="字数"
        prop="zishu">
      </el-table-column>
      <el-table-column
        align="right">
        <template slot="header">
          <el-input
            v-model="search"
            size="mini"
            placeholder="输入关键字搜索"/>
        </template>
        <template slot-scope="scope" >
          <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">Edit
          </el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">Delete
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<style scoped>
.cx{
  display: none;
}
</style>
